class GridSpace:

	def __init__(self, time, numPeople):
		self.lastObserved = time
		self.numPeople = numPeople

	def getNumPeople(self):
		return self.numPeople

	def getLastObserved(self):
		return self.lastObserved

	def makeObservation(self, time, people):
		self.numPeople = people
		self.lastObserved = time

class LastObservationMap:

	def __init__(self, cellSize, time):
		self.grid = [ [GridSpace(time, 0.0), GridSpace(time, 0.0)], [GridSpace(time, 0.0), GridSpace(time, 0.0)] ]
		self.minX = -cellSize
		self.minY = -cellSize
		self.maxX = cellSize
		self.maxY = cellSize

	def makeObservation(self, x, y, time, people):

		while x < self.minX:
			numNewColumns = -self.minX / cellSize
			height = len(self.grid[0])
			for i in range(numNewColumns):
				self.grid.insert(0, [])
				for j in range(height):
					self.grid[0].append([GridSpace(0.0, 0.0)])
			self.minX *= 2.0
		while x > self.maxX:
			numNewColumns = self.maxX / cellSize
			height = len(self.grid[0])
			for i in range(numNewColumns):
				self.grid.append([])
				for j in range(height):
					self.grid[len(self.grid) - 1].append([GridSpace(0.0, 0.0)])
			self.maxX *= 2.0
		while y < self.minY:
			numNewRows = -self.minY / cellSize
			for i in range(numNewRows):
				for j in range(len(self.grid)):
					self.grid[i].insert(0, GridSpace(0.0, 0.0))
			self.minY *= 2.0

		while y > self.maxY:
			numNewRows = self.maxY / cellSize
			for i in range(numNewRows):
				for j in range(len(self.grid)):
					self.grid[i].append(GridSpace(0.0, 0.0))
			self.maxY *= 2.0

		adjX = x - self.minX
		adjY = y - self.minY

		grid[adjX / cellSize][adjY / cellSize].makeObservation(time, people)
